/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import footprintscrollbar.FootprintScrollBar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import model.Model;
import model.Phrase;
import view.View;

/**
 *
 * @author mehlicious, karsonbraaten
 */
public class Controller {
    FootprintScrollBar scrollbar;
    Model model;
    View view;
    
    /**
     * The key to be held down when selecting a footprint
     */
    char FOOTPRINT_KEY = 'b';
    /**
     * A flag for whether or not the click will be on a footprint
     */
    boolean FOOTPRINT_CLICK = false;
    
    public Controller(Model m, View v, FootprintScrollBar f){
        scrollbar = f;
        model = m;
        view = v;

        view.startButton.addActionListener(new StartActionPerformed());
        view.foundButton.addActionListener(new FoundActionPerformed());
    }
 

    public class StartActionPerformed implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            Phrase p = model.getPhrase();
            view.highlightText(p);
            view.setSearchText(p);
            
            model.startTime();
            view.startButton.setEnabled(false);
            
            view.foundButton.setEnabled(true);
            
            scrollbar.requestFocus();
        }
    }
    
    public class FoundActionPerformed implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            //model.found();
            view.getTextArea();

            if(model.found(view._textArea)){
                Phrase p = model.getPhrase();
                if(p != null){
                    view.highlightText(p);
                    view.setSearchText(p);
                }
            }
            if(model.done){
                view.foundButton.setEnabled(false);
                model.writeDataToFile();
            }            scrollbar.requestFocus();
        }
        
    }

}
